package algorithmTopics.link;

import java.util.*;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 读取头节点
        String[] line1 = sc.nextLine().split(" ");
        // 头节点
        String head = line1[0];
        //节点个数
        Integer num = Integer.parseInt(line1[1]);
        // 读取所有节点
        // 存储
        Map<String,pair<String,String>> map = new HashMap<>();
        for (int i = 0; i < num; i++) {
            String[] line = sc.nextLine().split(" ");
            map.put(line[0], new pair<String,String>(line[1], line[2]));
        }
        String res = "";
        //开始寻找
        for (int i = 0; i <= num / 2; i++) {
            pair<String,String> p = map.get(head);
            res = p.getK();
            head = p.getV();
        }
        sc.close();
        System.out.println(res);
    }

    static class pair<K,V> {
        K k;
        V v;
        public pair(K k ,V v){
            this.k = k;
            this.v = v;
        }
        K getK(){return this.k;}
        V getV(){return this.v;}
    }
}